package org.come.Jpanel;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import org.come.until.ScrollUI;
import org.come.until.SrcollPanelUI;

import com.tool.btn.FactionBtn;
import com.tool.btn.FormsOnOffBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



/**
 * 帮战战报面板 编号:49
 * 
 * @author HGC<br>
 * @time 2020年1月13日 下午1:47:43<br>
 * @class 类名:FactionDetailsJpanel<br>
 */
public class FactionDetailsJpanel extends JPanel {

    private JScrollPane scrollPane;

    private JTable table;
    private DefaultTableModel tableModel;

    private FactionBtn btnExpel, btnAddFriend;

    public FactionDetailsJpanel() {
        setPreferredSize(new Dimension(662, 475));
        setOpaque(false);
        setLayout(null);
        if("水墨UI".equals(MyIsif.getStyle())) {
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 49);
            offBtn.setBounds(662 - 37, 10, 25, 25);
            this.add(offBtn);
        }else{
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("skin/8100226/button/s74.png", 1, 49);
            offBtn.setBounds(637, 1, 25, 25);
            this.add(offBtn);
        }

        getScrollPane();
        getBtnExpel();
        getBtnAddFriend();

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if("水墨UI".equals(MyIsif.getStyle())) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/old/background/S171.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 662, 475, null);

        }else{
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/2/S171.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 662, 475, null);
        }
    }

    public JTable getTable() {
        if (table == null) {
            table = new JTable() {
                @Override
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            };

            // 帮派成员信息表格
            table.setShowGrid(false);
            table.setOpaque(false);

            DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    // if (row < 3)
                    // setForeground(Color.yellow);
                    // else
                    setForeground(Color.white);

                    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            };
            renderer.setHorizontalAlignment(SwingConstants.CENTER);
            table.setDefaultRenderer(Object.class, renderer);

            JTableHeader header = table.getTableHeader();

            // 设置表头的高度
            header.setPreferredSize(new Dimension(header.getWidth(), 0));
            table.getTableHeader().setBackground(UIUtils.Color_BACK);
            table.getTableHeader().setVisible(true);
            table.getTableHeader().setBorder(BorderFactory.createLineBorder(Color.ORANGE));

            table.setSelectionBackground(UIUtils.Color_BACK);
            table.setSelectionForeground(Color.white);
            table.setForeground(Color.white);
            table.setFont(UIUtils.TEXT_FONT);
            table.setBackground(UIUtils.Color_BACK);
            table.setModel(getTableModel());

            // 设置列间距590
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(1).setPreferredWidth(80);
            table.getColumnModel().getColumn(2).setPreferredWidth(80);
            table.getColumnModel().getColumn(3).setPreferredWidth(70);
            table.getColumnModel().getColumn(4).setPreferredWidth(70);
            table.getColumnModel().getColumn(5).setPreferredWidth(60);
            table.getColumnModel().getColumn(6).setPreferredWidth(60);
            table.getColumnModel().getColumn(7).setPreferredWidth(80);
            // 设置行宽
            table.setRowHeight(25);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            table.isCellEditable(1, 1);
            table.setEnabled(true);
        }
        return table;
    }

    public void setTable(JTable table) {
        this.table = table;
    }

    public DefaultTableModel getTableModel() {
        if (tableModel == null) {
            tableModel = new DefaultTableModel();
            Vector<Vector<String>> verVectors = new Vector<Vector<String>>();
            for (int i = 0; i < 50; i++) {
                Vector<String> vector = new Vector<>();
                for (int j = 0; j < 8; j++) {
                    vector.add(String.valueOf(j + 1));
                }
                verVectors.add(vector);
            }
            Vector<String> vector3 = new Vector<String>();
            vector3.add("");
            vector3.add("");
            vector3.add("");
            vector3.add("");
            vector3.add("");
            vector3.add("");
            vector3.add("");
            vector3.add("");
            tableModel.setDataVector(verVectors, vector3);
        }
        return tableModel;
    }

    public void setTableModel(DefaultTableModel tableModel) {
        this.tableModel = tableModel;
    }

    public JScrollPane getScrollPane() {
        if (scrollPane == null) {
            scrollPane = new JScrollPane(getTable());
            scrollPane.setBounds(51, 51, 590, 372);
            scrollPane.setOpaque(false);
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            scrollPane.getVerticalScrollBar().setUI(new ScrollUI());
            scrollPane.getVerticalScrollBar().setUnitIncrement(30);
            scrollPane.setBorder(BorderFactory.createEmptyBorder());
            scrollPane.getViewport().setOpaque(false);
            this.add(scrollPane);
        }
        return scrollPane;
    }

    public void setScrollPane(JScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public FactionBtn getBtnExpel() {
        if (btnExpel == null) {
            if("水墨UI".equals(MyIsif.getStyle())) {
                btnExpel = new FactionBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_BLACK, "逐出", UIUtils.TEXT_HY16, 12,
                        this);
                btnExpel.setBounds(440, 432, 59, 24);

            }else{
                btnExpel = new FactionBtn("inkImg/hongmu/1/6026.png", 1, UIUtils.COLOR_BTNPUTONG, "逐出", UIUtils.TEXT_HY88, 12,
                        this);
                btnExpel.setBounds(440, 432, 60, 26);
            }
            this.add(btnExpel);
        }
        return btnExpel;
    }

    public void setBtnExpel(FactionBtn btnExpel) {
        this.btnExpel = btnExpel;
    }

    public FactionBtn getBtnAddFriend() {
        if (btnAddFriend == null) {
            if("水墨UI".equals(MyIsif.getStyle())) {
                btnAddFriend = new FactionBtn("skin/8100226/newbutton/B22.png", 1, UIUtils.COLOR_BLACK, "加为好友",
                        UIUtils.TEXT_HY16, 14, this);
                btnAddFriend.setBounds(513, 432, 99, 24);

            }else{
                btnAddFriend = new FactionBtn("inkImg/hongmu/1/1_png.button.btn_xy.png", 1, UIUtils.COLOR_BTNPUTONG, "加为好友",
                        UIUtils.TEXT_HY88, 14, this);
                btnAddFriend.setBounds(513, 432, 80, 26);
            }
            this.add(btnAddFriend);
        }
        return btnAddFriend;
    }

    public void setBtnAddFriend(FactionBtn btnAddFriend) {
        this.btnAddFriend = btnAddFriend;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

}
